package com.yx1996.test.day01;


import com.yx1996.bean.day01.CollectionBean;
import com.yx1996.bean.day01.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

//测试第一个bean
public class test1 {

    @Test
    //user创建方式1空参方法:ApplicationContext获得（调用user空参方法）
    public void fun1(){
        //获得application对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext01.xml");
        //从对象中获得user对象
        User user = (User) ac.getBean("user5");
        //输出user对象
        System.out.println(user);
    }
    @Test
    //user创建方式2静态工厂:创建一个工厂类里面有静态的user生成方法
    public void fun2(){
        //获得application对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext01.xml");
        //从对象中获得user对象
        User user = (User) ac.getBean("user2");
        //输出user对象
        System.out.println(user);
    }
    @Test
    //user创建方式3实例工厂:创建一个工厂类里面有实例化user的方法（先创建这个类在实例化user）
    public void fun3(){
        //获得application对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext01.xml");
        //从对象中获得user对象
        User user = (User) ac.getBean("user3");
        //输出user对象
        System.out.println(user);
    }

    @Test
    //测试复杂类型的注入
    public void fun4(){
        //获得application对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext01.xml");
        //从对象中获得user对象
        CollectionBean cb = (CollectionBean) ac.getBean("cb");
        //输出user对象
        System.out.println(cb);
    }
}
